package cn.com.dhc.danlu.business.shopcar.bean;

import java.math.BigDecimal;
import java.util.List;

import cn.com.dhc.danlu.business.shopcar.typefactory.IShopCarTypeFactory;
import cn.com.hd.mall.web.webservices.entity.response.shoppingcart.ToShoppingcartResponse.SellerListBean.MerchListBean.PromotionModelListBean;

/**
 * author: 李一方(<a href="mailto:liyifang@danlu.com">liyifang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-02-27 16:58
 *
 * <p>
 * 商品信息区域
 * </p>
 */
public class MerchBean extends ShopCarItem {
    // 增补信息区域
    /**
     * 商家 UI index
     */
    private int sellerIndex;
    /**
     * 选中的优惠促销 index
     */
    private int selPromotionIndex;
    /**
     * 产品均价
     */
    private BigDecimal averagePrice;

    // 商品实际字段区域
    private String id;
    private String merchId;
    private String merchName;
    private String merchBarCode;
    private String merchQuantity;
    private String picUrl;
    private String specName;
    private String priceRetail;
    private String priceDanlu;
    private String unitPrice;
    private String merchStatus;
    private String onHandInventory;
    private String sellerId;
    private String sellerName;
    private String returnFlag;
    private String miniStartSaleQuantityChanged;

    private List<PromotionModelListBean> promotionModelList;

    @Override
    public int type(IShopCarTypeFactory factory) {
        return factory.type(this);
    }

    // 增补信息区域
    public int getSellerIndex() {
        return sellerIndex;
    }

    public void setSellerIndex(int sellerIndex) {
        this.sellerIndex = sellerIndex;
    }

    // 商品实际字段区域
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getMerchId() {
        return merchId;
    }

    public void setMerchId(String merchId) {
        this.merchId = merchId;
    }

    public String getMerchName() {
        return merchName;
    }

    public void setMerchName(String merchName) {
        this.merchName = merchName;
    }

    public String getMerchBarCode() {
        return merchBarCode;
    }

    public void setMerchBarCode(String merchBarCode) {
        this.merchBarCode = merchBarCode;
    }

    public String getMerchQuantity() {
        return merchQuantity;
    }

    public void setMerchQuantity(String merchQuantity) {
        this.merchQuantity = merchQuantity;
    }

    public String getPicUrl() {
        return picUrl;
    }

    public void setPicUrl(String picUrl) {
        this.picUrl = picUrl;
    }

    public String getSpecName() {
        return specName;
    }

    public void setSpecName(String specName) {
        this.specName = specName;
    }

    public String getPriceRetail() {
        return priceRetail;
    }

    public void setPriceRetail(String priceRetail) {
        this.priceRetail = priceRetail;
    }

    public String getPriceDanlu() {
        return priceDanlu;
    }

    public void setPriceDanlu(String priceDanlu) {
        this.priceDanlu = priceDanlu;
    }

    public String getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(String unitPrice) {
        this.unitPrice = unitPrice;
    }

    public String getMerchStatus() {
        return merchStatus;
    }

    public void setMerchStatus(String merchStatus) {
        this.merchStatus = merchStatus;
    }

    public String getOnHandInventory() {
        return onHandInventory;
    }

    public void setOnHandInventory(String onHandInventory) {
        this.onHandInventory = onHandInventory;
    }

    public String getSellerId() {
        return sellerId;
    }

    public void setSellerId(String sellerId) {
        this.sellerId = sellerId;
    }

    public String getSellerName() {
        return sellerName;
    }

    public void setSellerName(String sellerName) {
        this.sellerName = sellerName;
    }

    public List<PromotionModelListBean> getPromotionModelList() {
        return promotionModelList;
    }

    public void setPromotionModelList(List<PromotionModelListBean> promotionModelList) {
        this.promotionModelList = promotionModelList;
        setSelPromotionIndex(promotionModelList.size());
    }

    public int getSelPromotionIndex() {
        return selPromotionIndex;
    }

    public void setSelPromotionIndex(int selPromotionIndex) {
        this.selPromotionIndex = selPromotionIndex;
    }

    public BigDecimal getAveragePrice() {
        return averagePrice;
    }

    public void setAveragePrice(BigDecimal averagePrice) {
        this.averagePrice = averagePrice;
    }

    public String getReturnFlag() {
        return returnFlag;
    }

    public void setReturnFlag(String returnFlag) {
        this.returnFlag = returnFlag;
    }

    public String getMiniStartSaleQuantityChanged() {
        return miniStartSaleQuantityChanged;
    }

    public void setMiniStartSaleQuantityChanged(String miniStartSaleQuantityChanged) {
        this.miniStartSaleQuantityChanged = miniStartSaleQuantityChanged;
    }

    /**
     * 判断是否有选择了优惠
     *
     * @return true - 有优惠
     */
    public boolean isSelPromotion() {
        return isValidPromotion(this.selPromotionIndex);
    }

    /**
     * 判定是否是有效的促销信息
     *
     * @param selIndex
     *         选中的促销 index
     *
     * @return true - 有效 index
     */
    public boolean isValidPromotion(int selIndex) {
        return null != this.getPromotionModelList()
                && !this.getPromotionModelList().isEmpty()
                && selIndex >= 0
                && selIndex < this.getPromotionModelList().size();
    }

    /**
     * 获取选择的优惠的信息
     */
    public String getSelPromotionInfo() {
        if (isSelPromotion()) {
            return this.promotionModelList.get(this.selPromotionIndex).getPromotionInfo();
        } else {
            return "-1";
        }
    }

    /**
     * 获取选择的促销类型
     */
    public String getSelPromotionType() {
        if (isSelPromotion()) {
            return this.promotionModelList.get(this.selPromotionIndex).getPromotionType();
        } else {
            return "-1";
        }
    }

    /**
     * 获取满减的类型
     *
     * @return 0-减单价 1-减总额
     */
    public String getReduceType() {
        if (isSelPromotion() && getSelPromotionType().equals("1")) {
            return this.promotionModelList.get(this.selPromotionIndex).getReductionType();
        } else {
            return "-1";
        }
    }

    public String getLimitLeftTimes() {
        if (isSelPromotion() && getSelPromotionType().equals("4")) {
            return this.promotionModelList.get(this.selPromotionIndex).getLimitRuleList().get(0).getLimitNumber();
        } else {
            return "-1";
        }
    }

    public String getIsPromotion() {
        if (isSelPromotion()) {
            return this.promotionModelList.get(this.selPromotionIndex).getIsPromotion();
        } else {
            return "0";
        }
    }

}
